//
//  XLAccountManageViewController.m
//  Mine
//
//  Created by 于鹏 on 2017/8/30.
//  Copyright © 2017年 YIVIEW. All rights reserved.
//

#import "XLAccountManageViewController.h"
#import "XLMineBaseCellModel.h"
#import "XLMineChangePwdViewController.h"
#import "UIView+Frame.h"
#import "UIView+XLVisuals.h"
#import "Lothar+Login.h"
#import "Lothar+Main.h"
//#import <BaseModule/UIView+Frame.h>
//#import <BaseModule/UIView+XLVisuals.h>
//#import <Login_Category/Lothar+Login.h>
//#import <Main_Category/Lothar+Main.h>
@interface XLAccountManageViewController ()

@end

@implementation XLAccountManageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"账号管理";
    XLWeakSelf(self);
    XLMineBaseCellModel *model = [[XLMineBaseCellModel alloc]initWithTitle:@"修改密码" actionBlock:^(XLMineBaseCellModel *model, NSIndexPath *indexPath) {
        XLMineChangePwdViewController *viewController = [[XLMineChangePwdViewController alloc]init];
        [weakself.navigationController pushViewController:viewController animated:YES];
    }];
    [self.xl_dataSource addObject:@[model]];
    [self.tableView reloadData];
    self.tableHeaderView = [self defaultTableHeader];
    self.tableView.tableFooterView = [self creatFooterView];
}

#pragma mark - footer
- (UIView *)creatFooterView {
    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight-20-44)];
    UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [deleteButton setTitle:@"退出账号" forState:UIControlStateNormal];
    CGFloat margin = 30;
    CGSize buttonSize = CGSizeMake(footerView.width-margin*2, 50);
    deleteButton.frame = CGRectMake(margin, footerView.height-200-buttonSize.height, buttonSize.width, buttonSize.height);
    [deleteButton xl_cornerRadius:buttonSize.height/2 strokeSize:1 color:kXLButtonColor_BLUE];
    deleteButton.backgroundColor = kXLButtonColor_BLUE;
    [footerView addSubview:deleteButton];
    [deleteButton addTarget:self action:@selector(loginOut:) forControlEvents:UIControlEventTouchUpInside];
    return footerView;
}

#pragma mark - 退出
- (void)loginOut:(UIButton *)sender {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setValue:UserInfo.userID forKey:@"doctorID"];
    [parameters setValue:UserInfo.tokenCode forKey:@"token"];
    [self showWithStatus:@"正在退出..."];
    [XLHTTPRequest UM_loginOutWithParameters:parameters success:^(id responseObject) {
        if ([responseObject[@"status"] isEqualToString:@"1"]) {
            [UserInfo loginOut];
            UIViewController *loginVC = [[Lothar shared]login_aViewController];
            [[Lothar shared] main_setNavBarRootViewController:loginVC];
        } else {
            
        }
    } failure:^(NSError *error, NSString *info) {
            if (error == nil) {
                [self exitLogin:info];
            }
        }];
}

- (void)initData {
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
